home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE23
/
CLINIC
/
APP1U.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-04-28
|
2KB
|
80 lines
unit App1U;
interface
uses
WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TControllerMainForm = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
ControllerMainForm: TControllerMainForm;
implementation
{$R *.DFM}
procedure ActivateWindow(Caption, ClassName: PChar);
var
FormWnd, AppWnd: HWnd;
begin
FormWnd := FindWindow(ClassName, Caption);
if FormWnd = 0 then
raise Exception.Create('Cannot find window');
{$ifdef Win32}
{ Having found the form, now find the Application window }
{ Can't reliably use GetParent, so... }
AppWnd := GetWindowLong(FormWnd, gwl_HWndParent);
{ Tell the Delphi Application window to pop up in case it }
{ is minimised. Bear in mind that FindWindow only works on }
{ top-level windows, not child windows. Delphi forms are }
{ top-level popup windows which have parents, so the following }
{ check should only try and restore a parent window if it }
{ is a Delphi app }
if (AppWnd <> HWnd_Desktop) and IsIconic(AppWnd) then
SendMessage(AppWnd, wm_SysCommand, sc_Restore, 0);
{ Tell the form window to pop up if it is minimised }
if IsIconic(FormWnd) then
SendMessage(FormWnd, wm_SysCommand, sc_Restore, 0);
{ Make the target form be in front and active }
SetForegroundWindow(FormWnd);
{$else}
AppWnd := GetWindowWord(FormWnd, gww_HWndParent);
if (AppWnd <> HWnd_Desktop) and IsIconic(AppWnd) then
SendMessage(AppWnd, wm_SysCommand, sc_Restore, 0);
if IsIconic(FormWnd) then
SendMessage(FormWnd, wm_SysCommand, sc_Restore, 0);
BringWindowToTop(FormWnd);
{$endif}
end;
procedure TControllerMainForm.Button1Click(Sender: TObject);
begin
ActivateWindow('MainForm', 'TMainForm')
end;
procedure TControllerMainForm.Button2Click(Sender: TObject);
begin
ActivateWindow('SecondaryForm', 'TSecondaryForm')
end;
procedure TControllerMainForm.Button3Click(Sender: TObject);
begin
ActivateWindow(nil, 'XLMAIN')
end;
end.